/**
 * creater:chuanpeng.zhu@dhc.com.cn
 * create time:2016/6/30
 * describe：todo
 **/
angular.module('select-group.directive', [])
    .directive('selectGroup', ['$state', '$ionicScrollDelegate', '$timeout',
        function ($state, $timeout) {
            return {
                restrict: 'E',
                replace: true,
                scope: {
                    selectGroup: '=selectGroup',
                    selectedIndex: '=selectedIndex',
                    attrName: '@attrName',
                    type: '@type'
                },
                template: '<ng:include src="template"/>',
                link: function (scope, element, attr, controller) {
                    console.log(scope.selectGroup);
                    if (!scope.type || scope.type < 1) {
                        scope.type = 1
                    }
                    if (scope.attrName) {
                        for (var i = 0; i < scope.selectGroup.length; i++) {
                            scope.selectGroup[i].title = scope.selectGroup[i][scope.attrName];
                        }
                    }
                    scope.template = "select-group" + scope.type + '.html';

                    /**
                     * 点击按钮选择方法
                     * @param index
                     */
                    scope.doSelectGroup = function (index) {
                        scope.selectedIndex = index;
                    }


                }
            }
        }]);